home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 19 / Amiga Plus Leser CD 19.iso / Tools / Development / source-highlight-1.6.1 / tests / test.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-11-17  |  2.3 KB  |  91 lines

  1. /*
  2. ** Copyright (C) 1999, 2000, 2001 Lorenzo Bettini <bettini@gnu.org>
  3. **  
  4. ** This program is free software; you can redistribute it and/or modify
  5. ** it under the terms of the GNU General Public License as published by
  6. ** the Free Software Foundation; either version 2 of the License, or
  7. ** (at your option) any later version.
  8. **  
  9. ** This program is distributed in the hope that it will be useful,
  10. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ** GNU General Public License for more details.
  13. **  
  14. ** You should have received a copy of the GNU General Public License
  15. ** along with this program; if not, write to the Free Software
  16. ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. **  
  18. */
  19.  
  20. // textgen.h : Text Generator class &&
  21.  
  22. #ifndef _TEXTGEN_H
  23. #define _TEXTGEN_H
  24.  
  25. #include <iostream.h>
  26.  
  27. #include "genfun.h"
  28.  
  29. class TextGenerator {
  30.   public :
  31.     virtual void generate( const char *s ) const { (*sout) << s ; }
  32.     virtual void generate( const char *s, int start, int end ) const 
  33.       {
  34.         for ( int i = start ; i <= end ; ++i )
  35.           (*sout) << s[i] ;
  36.       }
  37.     virtual void generateln( const char *s ) const
  38.     { 
  39.         generate( s ) ;
  40.         (*sout) << endl ; 
  41.     }
  42.     virtual void generateEntire( const char *s ) const
  43.     {
  44.         startTextGeneration() ;
  45.         generate(s) ;
  46.         endTextGeneration() ;
  47.     }
  48.     virtual void startTextGeneration() const {}
  49.     virtual void endTextGeneration() const {}
  50.     virtual void beginText( const char *s ) const
  51.     {
  52.         startTextGeneration() ;
  53.         if ( s )
  54.         generate( s ) ;
  55.     }
  56.     virtual void endText( const char *s ) const
  57.     {
  58.         if ( s )
  59.         generate( s ) ;
  60.         endTextGeneration() ;
  61.     }
  62. } ;
  63.  
  64. // Decorator
  65. class TextDecorator : public TextGenerator {
  66.   protected :
  67.     TextGenerator *decorated ;
  68.   
  69.   public :
  70.     TextDecorator( TextGenerator *t ) : decorated( t ) {}
  71.  
  72.     virtual void startTextGeneration() const 
  73.     { 
  74.     startDecorate() ;
  75.     if ( decorated )
  76.         decorated->startTextGeneration() ;
  77.     }
  78.     virtual void endTextGeneration() const 
  79.     { 
  80.     if ( decorated )
  81.         decorated->endTextGeneration() ;
  82.     endDecorate() ;
  83.     }
  84.  
  85.     // pure virtual functions
  86.     virtual void startDecorate() const = 0 ;
  87.     virtual void endDecorate() const = 0 ;
  88. } ;
  89.  
  90. #endif
  91.